package com.min.star.service.impl;

import java.util.Arrays;
import java.util.List;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.min.star.mapper.GradeMapper;
import com.min.star.model.Grade;
import com.min.star.model.Systeminfo;
import com.min.star.service.IGradeService;

@Service
public class GradeServiceImpl implements IGradeService {

	@Autowired
	private GradeMapper gradeMapper;

	@Override
	public List<Grade> selectGradeList() {
		return this.gradeMapper.selectList(null);
	}

	@Override
	public Page<Grade> selectPage(Page<Grade> page) {
		return this.gradeMapper.selectPage(page, null);
	}

	@Override
	public Page<Grade> findPage(Page<Grade> page, Grade grade) {
		return this.gradeMapper.findPage(page,grade);
	}

	@Override
	public int delete(String gradeIds) {
		return this.gradeMapper.deleteBatchIds(Arrays.asList(gradeIds.split(",")));
	}

	@Override
	public boolean checkgradeExist4Add(Grade grade) {
		//查询的包装器，里面存放各种查询条件
		QueryWrapper<Grade> queryWrapper = new QueryWrapper<Grade>();
		queryWrapper.lambda().eq(Grade::getStuId, grade.getStuId());
		queryWrapper.lambda().eq(Grade::getCurId, grade.getCurId());
		queryWrapper.lambda().eq(Grade::getSemester, grade.getSemester());
		int count = this.gradeMapper.selectCount(queryWrapper);
		return count == 0 ? false : true;
	}

	@Override
	public Grade save(Grade grade) {
		int ret = gradeMapper.insert(grade);
		Long id = grade.getId();
		Grade info = gradeMapper.findById(id);
		return info;
	}

	@Override
	public int update(Grade grade) {
		return this.gradeMapper.updateById(grade);
	}

	@Override
	public Grade findById(Long id) {
		return this.gradeMapper.findById(id);
	}
	
}
